package cn.pcios.kindle.scheduler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import cn.pcios.kindle.util.MultiThreadRead;

@Component  
public class Scheduler {  
	private static final Logger logger = LoggerFactory.getLogger(Scheduler.class); 
	
  @Autowired
  private MultiThreadRead multiThreadRead;
  /**
   * 查询封推书籍,保存到epub表,会发起网络请求
   * 使用myExecutor 线程池
   * fixedDelay=1000*60*60*24*6
   * */
  
 
  
  
  @Scheduled(fixedDelay=1000) 
  
  public void SchedulerJobAllTask() {
	 // multiThreadRead.getMate();
	 multiThreadRead.taskMOblieMateRead();
	  multiThreadRead.EpubToTask();
	 multiThreadRead.deleteFileTasks();
	 multiThreadRead.getMobiSendKindleEmail();
	 multiThreadRead.getFileTasks();
  }
  
  //@Scheduled(fixedDelay=1000*60*60*24*6) 
  @Deprecated
  public void taskMOblieMateRead() {  
	  
	  logger.debug("taskMOblieMateRead::每12小时抓取手机数据。开始……");  
	  try {
      	  multiThreadRead.taskMOblieMateRead();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	  logger.debug("taskCoverrecRead::结束……"); 
  }
  //@Scheduled(fixedDelay=1000*60*60*24*6) 
  
  @Deprecated
  public void taskCoverrecRead() {  
	  
	  logger.debug("taskCoverrecRead::每12小时抓取封推往期。开始……");  
	  try {
      	  multiThreadRead.taskCoverrecRead();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	  logger.debug("taskCoverrecRead::结束……"); 
  }
  /**
   * 查询三江书籍,保存到epub表,会发起网络请求
   * 使用myExecutor 线程池
   * fixedDelay=1000*60*60*24*6
   * */
 // @Scheduled(fixedDelay=1000*60*60*24*6) 
  
  @Deprecated
  public void taskSanjiangRead() {   
	  logger.debug("taskSanjiangRead::每12小时抓取三江往期。开始……");  
	  try {
      	multiThreadRead.startSanjiangRead();
      	
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	  logger.debug("taskCoverrecRead::结束……"); 
  }
  /**
   * 查询强推书籍,保存到epub表,会发起网络请求
   * 使用myExecutor 线程池
   * fixedDelay=1000*60*60*24*6
   * */
	//@Scheduled(fixedDelay=1000*60*60*24*6) 
	
	@Deprecated
    public void taskStrongrecRead() {      
        logger.debug("taskStrongrecRead::每12小时抓取强推往期。开始……");  
  
        try {
        	multiThreadRead.startStrongrecRead();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        logger.debug("taskStrongrecRead::结束……"); 
        
    }
	 /**
     * 定时任务下载书籍文件,会发起网络请求
     * 使用myExecutor 线程池
     * fixedDelay=10000
     * */
    //@Scheduled(fixedDelay=60*1000) 
    //
	@Deprecated
    public void getFileTasks() {      
        logger.debug("执行下载。开始……");  
    	
        try {
        	
        	multiThreadRead.getFileTasks();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    } 
	//@Scheduled(fixedDelay=10000)
	@Deprecated
    public void deleteFileTasks() {      
        logger.debug("删除失败文件。开始……");  
    	
        try {
        	
        	multiThreadRead.deleteFileTasks();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    } 
    /**
     * 转换epub任务
     * 使用myExecutor 线程池
     * fixedDelay=10000
     * */
   // @Scheduled(fixedDelay=10000)
    
    @Deprecated
    public void getEpubToTasks() {      
       
        try {
        	multiThreadRead.EpubToTask();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
	/**
	 * 发送到kindle
	 * 使用myExecutor 线程池
	 * fixedDelay=10000
	 * */
	//@Scheduled(fixedDelay=10000)
    @Deprecated
	public void getMobiSendKindleEmail() {      
	
	    try {
	    	multiThreadRead.getMobiSendKindleEmail();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} 
}  
